#include <iostream>
#include <vector>
#include <shared_mutex>
#include <mutex>
#include <thread>

namespace  shy
{
 class CalArray
 {
  private: 
    int _N; // num 
    int _M; // worker 
    int _num_work;
    std::vector<int> _S; 
    std::vector<std::mutex> _locks;

  public:
    CalArray(const int WorkerNum)
      :_N(100000),
      _M(WorkerNum),// M >=2
      _num_work(10000),
      _S(100000),
      _locks(100000)
    {}

    void Init()
    {
      for (auto& it : _S)
      {
        it = rand()%10;
      }
    }

    void work()
    {
      for (int it = 0; it < _num_work; it++)
      {
        int i = rand() % _N;
        int j = rand() % _N; 

        // get lock 
        _locks[i].lock();
        _locks[(i+1) % _N].lock();
        _locks[(i+2) % _N].lock();

        // calculate 
        int sum = _S[i] + _S[(i+1) % _N] + _S[(i+2) % _N];

        // free lock 
        _locks[i].unlock();
        _locks[(i+1) % _N].unlock();
        _locks[(i+2) % _N].unlock();

        // get lock 
        _locks[j].lock();


        // update S[j]
        _S[j] = sum;

        // free lock 
        _locks[j].unlock();
      }
    }

    void run()
    {
      std::vector<std::thread> threads;

      for (int i = 0; i < _M ; i++)
      {
        threads.emplace_back(&CalArray::work , this);
      }

      for (auto& t : threads)
      {
        t.join();
      }
    }

    void Print(int num)
    {
      for(int i = 0; i < num; i++)
      {
        std::cout << _S[i] << " " ;
      }
      std::cout << std::endl;
    }

    ~CalArray()
    {}
 };
}
int main()
{
  int M = 0;
  std::cin >> M ;
  if (M < 2 )
  {
    std::cerr << "workersnum error!" << std::endl;
    return -1;
  }

  shy::CalArray arr(M);
  arr.Init();
  arr.run();
  arr.Print(1000);
  return 0;
}

